package com.huluobo.base.db;

import android.app.Application;

import androidx.room.Room;

/**
 * Created by LC on 2024/9/4.
 */
public class AppDBUtils {
    private static AppDBUtils appDBUtils;
    private AppDatabase appDatabase;
    private UserDao userDao;
    private VideoDao videoDao;
    private MoneyDao moneyDao;

    private AppDBUtils() {
    }

    public static AppDBUtils getInstance() {
        if (appDBUtils == null) {
            synchronized (AppDBUtils.class) {
                if (appDBUtils == null) {
                    appDBUtils = new AppDBUtils();
                }
            }
        }
        return appDBUtils;
    }

    public void init(Application application) {
        appDatabase = Room.databaseBuilder(application, AppDatabase.class, "douyin.db")
                .allowMainThreadQueries()
                .build();
    }

    public UserDao getUserDao() {
        if (userDao == null) {
            userDao = appDatabase.getUserDao();
        }
        return userDao;
    }

    public VideoDao getVideoDao() {
        if (videoDao == null) {
            videoDao = appDatabase.getVideoDao();
        }
        return videoDao;
    }

    public MoneyDao getMoneyDao() {
        if (moneyDao == null) {
            moneyDao = appDatabase.getMoneyDao();
        }
        return moneyDao;
    }
}
